<template>
    <van-nav-bar :title="route.meta.title" left-arrow @click-left="router.back()" fixed placeholder></van-nav-bar>
    <van-form @submit="onSubmit" >
        <van-cell-group inset>
            <van-field v-model="security" name="security" label="密保" placeholder="密保"
                :rules="[{ required: true, message: '请填写密保' }]" />
            <van-field v-model="newPwd" type="password" name="newPwd" label="新密码" placeholder="新密码" :rules="[{ required: true, message: '请填写密码' }, {
                pattern: /^[-_a-zA-Z0-9]{6,16}$/,
                message: '只能包含6-16位字母数字下划线减号',
            },]" />
        </van-cell-group>
        <div style="margin: 16px;">
            <van-button round block type="primary" native-type="submit">
                提交
            </van-button>
        </div>
    </van-form>
</template>

<script setup>
import { useRouter, useRoute } from 'vue-router';
import { changePwd } from '@/api/auth.js'
import { showSuccessToast } from 'vant';
import { ref } from 'vue'
const router = useRouter()
const route = useRoute()
let security = ref('')
let newPwd = ref('')

let onSubmit = async ({security,newPwd}) => {
    let res = await changePwd({
        secret_answer: security,
        password: newPwd
    })
  /*   
    if (res.code == 1) {
        showSuccessToast({
            message: '修改成功',
        });
        router.push('login')
    }  */
}
</script>

<style lang="scss" scoped>
.van-form{
    margin-top: .5333rem;
}
</style>